<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8" />
<title>用户管理</title>

<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/icon.css">
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.min.js"></script>
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$('#mytable').datagrid({
		nowrap: false,
		striped: true,
		url:'<{:U("userjson")}>',
		loadMsg:'数据正在加载，请稍候...',
		columns:[[
			{field:'table_id',checkbox:true},
			{field:'table_account',title:'账户名称',width:150,align:"left"},
			{field:'table_name',title:'用户名称',width:150,align:"left"},
			{field:'table_email',title:'email',width:150,align:"left"},
			{field:'table_role',title:'用户角色',width:150,align:"left",formatter:function(value){
				return value.rolename;
			}}
		]],
		singleSelect:true,
		fit:true,
		pagination:true,
		pageSize:20,
		toolbar:[{
			text:'新增用户',
			iconCls:'icon-add',
			handler:addAction
		},'-',{
			text:'编辑用户',
			iconCls:'icon-edit',
			handler:editAction
		},'-',{
			text:'修改用户密码',
			iconCls:'icon-edit',
			handler:editActionPwd
		},'-',{
			text:'删除用户',
			iconCls:'icon-remove',
			handler:removeAction
		}]
	});
});
function addAction(){
	$("#form_role").val($("#form_role option:first").val());
	$("#form_area").val($("#form_area option:first").val());
	$("#form_email").val('');
	$("#form_name").val('');
	$("#form_password").val('');
	$("#submit").unbind("click");
	$("#submit").bind("click",{type:"add",action:'<{:U("useradd")}>'},checkSubmit);
	$("#formWindow").window('open');
	$("#myLayout").layout('resize');
}
function editAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个用户再编辑！','error');
	}else{
		$("#form_email2").val(selected.table_email);
		$("#form_name2").val(selected.table_name);
		$("#form_role2").val(selected.table_role.role);
		$("#submit2").unbind("click");
		$("#submit2").bind("click",{type:"edit",action:'<{:U("useredit")}>',table_id:selected.table_id},checkSubmit2);
		$("#formWindow2").window('open');
		$("#myLayout2").layout('resize');
	}
}
function editActionPwd(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个用户再编辑！','error');
	}else{
		$("#form_passwd3").val('');
		$("#submit3").unbind("click");
		$("#submit3").bind("click",{type:"editpwd",action:'<{:U("userpwd")}>',table_id:selected.table_id},checkSubmit3);
		$("#formWindow3").window('open');
		$("#myLayout3").layout('resize');
	}
}
function removeAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个用户再删除！','error');
	}else{
		$.messager.confirm('提示消息','确认删除？',function(r){
			if(r){
				$.post('<{:U("userremove")}>','form_id='+selected.table_id,function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.info,'error');
					}else{
						$.messager.alert('提示消息',data.info,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
function closeForm(){
	$("#formWindow").window('close');
}
function closeForm2(){
	$("#formWindow2").window('close');
}
function closeForm3(){
	$("#formWindow3").window('close');
}
function checkSubmit(event){
	if(!$("#myForm").form('validate')){
		$.messager.alert('错误消息','请确保表单信息无误再提交！','error');
	}else{
		closeForm();
		$.post(window.location.href,$('#myForm').serialize()+'&form_id='+event.data.table_id,function(data){
			if(data.status=='false'){
				$.messager.alert('错误消息',data.info,'error');
			}else{
				$.messager.alert('提示消息',data.info,'info',function(){
					$("#mytable").datagrid('reload');
				});
			}
		},"json"); 
	}
}
function checkSubmit2(event){
	if(!$("#myForm2").form('validate')){
		$.messager.alert('错误消息','请确保表单信息无误再提交！','error');
	}else{
		closeForm2();
		$.post(window.location.href,$('#myForm2').serialize()+'&submit='+event.data.type+'&form_id='+event.data.table_id,function(data){
			if(data.status=='false'){
				$.messager.alert('错误消息',data.msg,'error');
			}else{
				$.messager.alert('提示消息',data.msg,'info',function(){
					$("#mytable").datagrid('reload');
				});
			}
		},"json"); 
	}
}
function checkSubmit3(event){
	if(!$("#myForm3").form('validate')){
		$.messager.alert('错误消息','请确保表单信息无误再提交！','error');
	}else{
		closeForm3();
		$.post(window.location.href,$('#myForm3').serialize()+'&submit='+event.data.type+'&form_id='+event.data.table_id,function(data){
			if(data.status=='false'){
				$.messager.alert('错误消息',data.msg,'error');
			}else{
				$.messager.alert('提示消息',data.msg,'info',function(){
					$("#mytable").datagrid('reload');
				});
			}
		},"json"); 
	}
}
function searchres(){
	var username = encodeURIComponent($.trim($("#username").val()));
	$('#mytable').datagrid({pageNumber:'1',pageSize:'20',url:'ajax.php?act=user&username='+username});
}
</script>
</head>
<body class="easyui-layout">
<div region="center" title="系统设置-&gt;用户管理">
<div class="easyui-layout" fit="true">
	<div region="north" border="false" style="height:35px;padding:2px;padding-left:20px;background-color:#DFE8F6;font-size:11px;color:#15428B;"><table><tr><td>用户名称：</td><td><INPUT TYPE="text" NAME="username" id="username" style="width:180px;"></td><td><a class="easyui-linkbutton" icon="icon-search" onclick="searchres();">搜索</a></td></tr></table></div>
	<div region="center" border="true"><table id="mytable"></table></div>
</div>
</div>
<div id="formWindow" class="easyui-window" title="新增用户" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:550px;height:350px;padding:5px;">
	<div class="easyui-layout" fit="true" id="myLayout">
		<div region="center" border="false">
		<form id="myForm" method="post">
			<table>
				<tr><td>email：</td><td><INPUT class="easyui-validatebox" required="true" missingMessage="email不能为空" TYPE="text" NAME="form_email" id="form_email" style="width:250px"></td></tr>
				<tr><td>用户名称：</td><td><INPUT class="easyui-validatebox" required="true" missingMessage="用户名称不能为空" TYPE="text" NAME="form_name" id="form_name" style="width:250px"></td></tr>
				<tr><td>用户密码：</td><td><INPUT class="easyui-validatebox" required="true" validType="length[6,12]" missingMessage="用户密码不能为空，且密码为6到12位" invalidMessage="用户密码不能为空，且密码为6到12位" TYPE="text" NAME="form_passwd" id="form_passwd" style="width:250px"></td></tr>
				<tr><td>用户角色：</td><td><SELECT NAME="form_role" id="form_role" style="width:250px"><?=$roleSelectHtml?></SELECT></td></tr>
			</table>
		</form>
		</div>
		<div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
			<a class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" id="submit">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)" onclick="closeForm()">取消</a>
		</div>
	</div>
</div>
<div id="formWindow2" class="easyui-window" title="编辑用户" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:550px;height:300px;padding:5px;">
	<div class="easyui-layout" fit="true" id="myLayout2">
		<div region="center" border="false">
		<form id="myForm2" method="post">
			<table>
				<tr><td>email：</td><td><INPUT class="easyui-validatebox" required="true" missingMessage="email不能为空" TYPE="text" NAME="form_email2" id="form_email2" style="width:250px"></td></tr>
				<tr><td>用户名称：</td><td><INPUT class="easyui-validatebox" required="true" missingMessage="用户名称不能为空" TYPE="text" NAME="form_name2" id="form_name2" style="width:250px"></td></tr>
				<tr><td>用户角色：</td><td><SELECT NAME="form_role2" id="form_role2" style="width:250px"><?=$roleSelectHtml?></SELECT></td></tr>
			</table>
		</form>
		</div>
		<div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
			<a class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" id="submit2">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)" onclick="closeForm2()">取消</a>
		</div>
	</div>
</div>
<div id="formWindow3" class="easyui-window" title="修改用户密码" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:400px;height:150px;padding:5px;">
	<div class="easyui-layout" fit="true" id="myLayout3">
		<div region="center" border="false">
		<form id="myForm3" method="post">
			<table>
				<tr><td>用户新密码：</td><td><INPUT class="easyui-validatebox" required="true" validType="length[6,12]" missingMessage="用户密码不能为空，且密码为6到12位" invalidMessage="用户密码不能为空，且密码为6到12位" TYPE="text" NAME="form_passwd3" id="form_passwd3" style="width:250px"></td></tr>
			</table>
		</form>
		</div>
		<div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
			<a class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" id="submit3">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)" onclick="closeForm3()">取消</a>
		</div>
	</div>
</div>
</body>
</html>